#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 创建菜单栏
    QMenuBar* menuBar = new QMenuBar();
    // 放入窗口
    this->setMenuBar(menuBar);
    // 创建菜单
    QMenu* menu1 = new QMenu("文件(&A)");
    QMenu* menu2 = new QMenu("编辑");
    QMenu* menu3 = new QMenu("视图");
    // 添加菜单到菜单栏
    menuBar->addMenu(menu1);
    menuBar->addMenu(menu2);
    menuBar->addMenu(menu3);
    // 添加菜单项
    QAction* act1 = new QAction("打开(&N)");
    QAction* act2 = new QAction("另存为");
    QAction* act3 = new QAction("保存");
    QAction* act4 = new QAction("关闭(&d)");
    menu1->addAction(act1);
    menu1->addSeparator();
    menu1->addAction(act2);
    menu1->addAction(act3);
    menu1->addAction(act4);
    // slot函数
    connect(act1, &QAction::triggered, this, &MainWindow::handle);
    connect(act4, &QAction::triggered, this, &MainWindow::close);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle()
{
    qDebug() << "新建";
}

